define(["themelayer"],function (themelayer, control) {
    var Layer = {
        /**
         * 矢量：vec_w
         * 标注：cva_w
         * 影像：img_w
         * 影像标注：cia_w
         * 地形：ter_w
         */
        tdtUrl: "http://t{0-7}.tianditu.com/DataServer?T=#lyr#&X={x}&Y={y}&L={z}",

        /**
         * 矢量：m@189
         * 影像：s@189
         * 影像标注：h@189
         * 影像+标注：s@189,r@240000000或s@189,h@189
         * 地形：h@189, t@131
         * 地形+标注：t@131,r@240000000或h@189,r@240000000
         */
        googleUrl: "http://www.google.cn/maps/vt?lyrs=#lyr#&gl=cn&x={x}&y={y}&z={z}",

        /**
         * 温暖  warm
         * 清爽  cool
         * 午夜  midnight
         * 暗色  dark
         * 高对比  contrast
         * 浪漫粉  pink
         * 夜视  vision
         * 探险  adventure
         * 魅蓝  blue
         * 浅色  c
         * 清新  fresh
         * 自然  natural
         * 政区  admin
         * 旅游  tourism
         * 水系  river
         * 世界中文  chinese
         */
        geoheyUrl: "https://s{0-8}.geohey.com/s/mapping/#lyr#/all?z={z}&x={x}&y={y}&retina=&ak=MGUxMmI2ZTk4YTVhNDEzYmJhZDJkNDM3ZWI5ZDAwOGE",

        gaodeUrl: "http://webrd01.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=1&style=8",

        getLayer: function (lyrData) {
            var self = this;
            switch (lyrData.type){
                case "tile":{
                    return self.getTileLayer(lyrData.code, lyrData.layer)
                }
            }
        },

        getTileLayer: function(type, lyr) {
            var self = this;
            var source = self.getTileSource(self.getTileUrl(type, lyr));
            return new ol.layer.Tile({
                source: source
            })
        },

        getTileUrl: function (type, lyr) {
            var self = this;
            var layerUrl = {
                "tdt": self.tdtUrl,
                "google": self.googleUrl,
                "geohey": self.geoheyUrl,
                "gaode": self.gaodeUrl
            };
            var url = layerUrl[type];
            return url.replace("#lyr#", lyr);
        },

        getTileSource: function (url) {
            return new ol.source.XYZ({
                url:url
            })
        },

        /**
         * 添加专题图
         * @param type 专题图类型
         * @param layerData 图层数据，见具体的图层实现
         * @param style 样式表
         */
        addThemeLayer: function(type, layerData, style){
            themelayer.addLayer(type, layerData, style);
        },

        clearThemeLayer: function () {
            themelayer.clear();
        }
    };
    return Layer;
});